/**
    入驻小区
**/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            productPriceRuleManageInfo: {
                productPriceRules: [],
                total: 0,
                records: 1,
                moreCondition: false,
                ruleId: '',
                conditions: {
                    ruleId: '',
                    ruleName: '',
                    price: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function() {
            $that.productPriceRuleManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
            $that._listProductPriceRules(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function() {

            vc.on('productPriceRuleManage', 'listProductPriceRule', function(_param) {
                $that._listProductPriceRules(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listProductPriceRules(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listProductPriceRules: function(_page, _rows) {

                $that.productPriceRuleManageInfo.conditions.page = _page;
                $that.productPriceRuleManageInfo.conditions.row = _rows;

                let param = {
                    params: $that.productPriceRuleManageInfo.conditions
                };


                //发送get请求
                vc.http.apiGet('/productPriceRule.listProductPriceRule',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.productPriceRuleManageInfo.total = _json.total;
                        $that.productPriceRuleManageInfo.records = _json.records;
                        $that.productPriceRuleManageInfo.productPriceRules = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.productPriceRuleManageInfo.records,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddProductPriceRuleModal: function() {
                vc.emit('addProductPriceRule', 'openAddProductPriceRuleModal', {});
            },
            _openEditProductPriceRuleModel: function(_productPriceRule) {
                vc.emit('editProductPriceRule', 'openEditProductPriceRuleModal', _productPriceRule);
            },
            _openDeleteProductPriceRuleModel: function(_productPriceRule) {
                vc.emit('deleteProductPriceRule', 'openDeleteProductPriceRuleModal', _productPriceRule);
            },
            _queryProductPriceRuleMethod: function() {
                $that._listProductPriceRules(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _moreCondition: function() {
                if ($that.productPriceRuleManageInfo.moreCondition) {
                    $that.productPriceRuleManageInfo.moreCondition = false;
                } else {
                    $that.productPriceRuleManageInfo.moreCondition = true;
                }
            },
            _productUpdatePrice: function(_rule) {
                vc.emit('updateProductPrice', 'openUpdateProductPriceModel', {
                    ruleId: _rule.ruleId
                });
            },
            _getBase: function(_base) {
                if (_base == '2') {
                    return '销售价';
                } else if (_base == '3') {
                    return '市场价';
                } else if (_base == '4') {
                    return '业主价';
                } else if (_base == '5') {
                    return '会员价';
                }

                return '成本价'
            }
        }
    });
})(window.vc);